#include "register.h"
#include "ui_register.h"
#include "cmd.h"
#include <QMessageBox>
Register::Register(communicate *com,QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Register)
{
    ui->setupUi(this);
    this->com=com;
    connect(com,SIGNAL(rstResult(int)),this,SLOT(rstResult(int )));
}

Register::~Register()
{
    delete ui;
}



void Register::on_pushButton_clicked()
{
    QString username=ui->lineEdit->text();
    QString password=ui->lineEdit_2->text();
    //将注册信息发送到服务器
    QJsonObject json;
    json["cmd"]=REGISTER;
    json["userName"]=username;
    json["passwd"]=password;
    com->writeClientData(json);
}

void Register::rstResult(int ret)
{
    switch (ret) {
    case OK:

        QMessageBox::information(this,"注册","注册成功");
        break;
    case ERROR:
        QMessageBox::information(this,"错误","未知错误");
        break;
    case USEREXIST:
        QMessageBox::information(this,"注册","注册失败，用户已存在！");
        break;
    default:
        break;
    }

}

void Register::on_pushButton_2_clicked()
{
    this->close();
}
